package com.egao.common.publicly.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.egao.common.core.web.PageParam;
import com.egao.common.module.outer.entity.OuterPreach;
import com.egao.common.publicly.entity.PubliclyCareerVO;
import com.egao.common.publicly.mapper.PubliclyOuterPreachMapper;
import com.egao.common.publicly.service.PubliclyOuterPreachService;
import com.egao.common.publicly.utils.CalendarUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * 校外宣讲会
 *
 * @author pyx
 */
@Service
public class PubliclyOuterPreachServiceImpl extends ServiceImpl<PubliclyOuterPreachMapper, OuterPreach> implements PubliclyOuterPreachService {
    @Override
    public List<PubliclyCareerVO> listPage(PageParam<PubliclyCareerVO> pageParam) {
        CalendarUtils.putTime(pageParam);
        return baseMapper.listPage(pageParam);
    }

    @Override
    public OuterPreach getId(Integer id) {
        OuterPreach outerPreach = baseMapper.selectById(id);

        if (outerPreach == null) {
            return new OuterPreach();
        }

        //更新点击量
        if (outerPreach.getHits() == null) {
            outerPreach.setHits(0);
        }
        outerPreach.setHits(outerPreach.getHits() + 1);
        baseMapper.updateById(outerPreach);

        return outerPreach;
    }

    @Override
    public Integer allHists(HashMap<String, String> createTimeMap) {
        return baseMapper.allHists(createTimeMap);
    }
}
